<?php

class Encrypt extends Controller
{
	//$number = rand(163245,978534);
	
	/*
	 * $saltnumber: random number for encrypt
	 * $password: the input password
	 * */
	public static function encript($password, $saltnumber)
	{
	   $pass = crypt($password,$saltnumber);
	   return  Yii::app()->user->hashPassword($password.$saltnumber);
	}
	/*
	 * $password: password input from user
	 * $saltnumber: the number key save in user data 
	 * $dbpassword: the password encrypt
	 */
	public static function decript($password, $saltnumber, $dbpassword)
	{
	   $encriptpass = Yii::app()->user->hashPassword($password.$saltnumber);
	   print($encriptpass. "/". $dbpassword);
	   die();
	   if(strcmp($encriptpass , $dbpassword)==0)
	   	return true;
	   return false;
	}
	
	public static function generateNumber()
	{
		return rand(163245,978534);
	}
	
	public static function encodePassword($user){
		$user->Salt = Encrypt::generateNumber(); 
		$user->Password = Encrypt::encript($user->Password, $user->Salt);
	}
}